;; 添加lspmode for emacs.

;; provide by chenbin.
(with-eval-after-load 'lsp-mode
  ;; enable log only for debug
  (setq lsp-log-io nil)
  ;; use `evil-matchit' instead
  (setq lsp-enable-folding nil)
  ;; no real time syntax check
  (setq lsp-diagnostic-package :none)
  ;; handle yasnippet by myself
  (setq lsp-enable-snippet nil)
  ;; ;; use `company-ctags' only.
  ;; ;; Please note `company-lsp' is automatically enabled if it's installed
  ;; (setq lsp-enable-completion-at-point t)
  ;; ;; turn off for better performance
  ;; (setq lsp-enable-symbol-highlighting t)
  ;; use find-file-in-project instead
  (setq lsp-enable-links nil)
  ;; ;; auto restart lsp
  ;; (setq lsp-restart 'auto-restart)

  ;; don't watch 3rd party javascript libraries
  (push "[/\\\\][^/\\\\]*\\.\\(json\\|html\\|jade\\)$" lsp-file-watch-ignored)
  ;; don't ping LSP language server too frequently
  (defvar lsp-on-touch-time 0)


  (require 'lsp-ui)
  (lsp-ui-mode 1)
  ;; definitions for lsp-ui, with the xref
  (define-key lsp-ui-mode-map [remap xref-find-definitions] #'lsp-ui-peek-find-definitions)
  (define-key lsp-ui-mode-map [remap xref-find-references] #'lsp-ui-peek-find-references)

  (setq lsp-ui-doc-enable t)
  (setq lsp-ui-doc-delay 1.0)

  ;; (defun my-lsp-on-change-hack (orig-fun &rest args)
  ;;   ;; do NOT run `lsp-on-change' too frequently
  ;;   (when (> (- (float-time (current-time))
  ;;               lsp-on-touch-time) 120) ;; 2 mins
  ;;     (setq lsp-on-touch-time (float-time (current-time)))
  ;;     (apply orig-fun args)))
  ;; (advice-add 'lsp-on-change :around #'my-lsp-on-change-hack)
  )

;; (use-package lsp-ivy :commands lsp-ivy-workspace-symbol)
;; (use-package lsp-treemacs :commands lsp-treemacs-errors-list)

;; ;; optionally if you want to use debugger
;; (use-package dap-mode)
;; ;; (use-package dap-LANGUAGE) to load the dap adapter for your language

(provide 'init-lsp)

